<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.engine.common.util.ParamUtil" %>
<%@ page import="com.engine.workflow.biz.FormFieldSetBiz" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page pageEncoding="UTF-8" %>
<%
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/json; charset=utf-8");
    JSONObject json = new JSONObject();
    json.put("status", -1);
    PrintWriter writer = null;
    try {
        writer = response.getWriter();
        //获得登录用户
        User user = HrmUserVarify.getUser(request, response);
        if (user == null) {
            json.put("msg", "用户未登录");
            writer.write(json.toString());
            writer.close();
            return;
        }
        //获取请求参数
        Map<String, Object> params = ParamUtil.request2Map(request);
        //表单id
        int formId = Util.getIntValue(Util.null2String(params.get("formId")));
        //字段id
        int fieldId = Util.getIntValue(Util.null2String(params.get("fieldId")));
        new BaseBean().writeLog("formId:" + formId + ",fieldId:" + fieldId);
        //获取数据
        json.putAll(getData(formId, user, fieldId));
        json.put("status", 200);
        writer.println(json.toJSONString());
        writer.close();
    } catch (Exception e) {
        json.put("msg", e.getMessage());
        if (writer != null) {
            writer.println(json.toJSONString());
            writer.close();
        }
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
%>
<%!
    private Map<String, Object> getData(int formId, User user, int fieldId) {
        Map<String, Object> data = new HashMap<>();
        FormFieldSetBiz formFieldSetBiz = new FormFieldSetBiz(formId, 1, user, false);
        List<Object> fieldTypeData = formFieldSetBiz.getFieldTypeData(formId, fieldId);
        new BaseBean().writeLog("fieldTypeData:" + fieldTypeData);
        data.put("data", fieldTypeData);
        return data;
    }
%>